package com.ml.mall.api.order;

import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.BaseBeanReq;
import com.ml.mall.bean.req.order.OrderEditReq;
import com.ml.mall.bean.req.order.OrderPaymentDataQueryDto;
import com.ml.mall.bean.req.order.OrderNewReq;
import com.ml.mall.bean.req.order.OrderQueryPageReq;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.Valid;

import com.ml.mall.annotations.OperLog;
import com.ml.mall.service.order.SysOrderService;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;

/**
* <p>
*  前端控制器
* </p>
*
* @author kyyang
* Created 2021-05-24
*/

@Api(tags = "【order】订单")
@RestController
@RequestMapping("/order")
public class SysOrderController extends BaseController{

     @Autowired
     private SysOrderService sysOrderService;

    @RequestMapping(method = RequestMethod.POST, path = "/query_page")
    @ApiOperation("分页查询订单")
//    @RequiresPermissions(PermissionConst.ORDER_QUERY_PAGE)
    public ApiRestResult sysOrderQuery(@RequestBody OrderQueryPageReq req) {
        return ApiRestResult.ok(sysOrderService.sysOrderByPage(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/buyer/query_one")
    @ApiOperation("查询买家订单详情")
//    @RequiresPermissions(PermissionConst.ORDER_BUYER_QUERY_ONE)
    public ApiRestResult sysOrderBuyerQuery_one(@RequestBody BaseBeanReq req) {
        return ApiRestResult.ok(sysOrderService.sysOrderBuyerQuery_one(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "订单创建", operModul = "order", operType = "new")
    @ApiOperation("订单创建")
//    @RequiresPermissions(PermissionConst.ORDER_NEW)
    public ApiRestResult sysOrderNew(@Valid @RequestBody OrderNewReq orderNewReq ) throws NoSuchAlgorithmException {
        return ApiRestResult.ok(sysOrderService.sysOrderNew(orderNewReq));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @OperLog(operDesc = "订单修改", operModul = "order", operType = "edit")
    @ApiOperation("订单修改")
//    @RequiresPermissions(PermissionConst.ORDER_EDIT)
    public ApiRestResult sysOrderEdit(@Valid @RequestBody OrderEditReq orderEditReq ) {
        return ApiRestResult.ok(sysOrderService.sysOrderEdit(orderEditReq));
    }

    /*@RequestMapping(method = RequestMethod.POST, path = "/ceshi")
    @ApiOperation("测试")
    public ApiRestResult orderMailTemplateVO() {

        MailTemplateUtils mailTemplateUtils=new MailTemplateUtils();
        return ApiRestResult.ok(mailTemplateUtils.MailTeplate(sysOrderService.orderMailTemplateVO(172788183739L)));

    }*/

    @RequestMapping(method = RequestMethod.POST, path = "/payment_data/query")
    @ApiOperation("获取订单支付数据")
    public ApiRestResult orderPaymentData(@RequestBody @Valid OrderPaymentDataQueryDto dto) throws NoSuchAlgorithmException {
        return ApiRestResult.ok(sysOrderService.orderPaymentDataQuery(dto));
    }
}
